<template>
  <div class="approval">
    <el-card class="box-card" style="margin-top: 110px;">
      <div class="title">{{$t('achievements.title1')}}</div>
      <div class="menu-search">
        <div class="menu-title">
          <!-- 渠道 -->
          <div class='searchItem'>
            <span>{{$t('productManage.channels')}}</span>
            <el-select v-model='listQuery.channel' size='small'>
                <el-option
                v-for='item in appChannel'
                :key='item.channel'
                :label='item.org_name'
                :value='item.channel'>
                </el-option>
            </el-select>
          </div>
          <!-- 类型 -->
          <div class="searchItem">
            <span>{{$t('menu.type')}}</span>
            <el-select v-model="listQuery.type" filterable size="small">
              <el-option 
                v-for="item in typeArr"
                :key="item.value"
                :label="item.label"
                :value="item.value"></el-option>
            </el-select>
          </div>
          <!-- 支付渠道名称 -->
          <div class="searchItem">
            <span>{{$t('payChannelManager.payChannelName')}}</span>
            <el-input
              v-model="listQuery.payCompanyCode"
              size="small"
              :placeholder="$t('NoticeManager.inpSearchName')"
            ></el-input>
          </div>
          <div class="menu-title-btn" style="margin-left: 20px;">
            <button type="button" @click="search">{{$t('btn.query')}}</button>
          </div>
        </div>
      </div>
    </el-card>
    <el-card class="box-card" style="margin-top: 10px;margin-bottom: 20px;">
      <div style="display: flex; justify-content: space-between;">
        <div class="title">{{$t('DailyStatistics.ListDetails')}}</div>
      </div>
      <el-table
        v-loading="listLoading"
        ref="multipleTable"
        :data="tableData"
        tooltip-effect="dark"
        style="width: 100%; margin-top: 5px;"
        border
        size="mini"
      >
        <el-table-column
          :label="$t('RiskManager.number')"
          header-align="center"
          align="center"
          width="60"
        >
          <template slot-scope="scope">
            <span>{{scope.row.index}}</span>
          </template>
        </el-table-column>
        <!-- 支付渠道名称 -->
        <el-table-column
          header-align="center"
          align="center"
          prop="payCompanyCode"
          :label="$t('payChannelManager.payChannelName')"
        ></el-table-column>
        <!-- 状态 -->
        <el-table-column
          header-align="center"
          align="center"
          width="160"
          :label="$t('grouping.status')"
        >
          <template slot-scope="scope">
            <el-radio-group v-model="scope.row.status" size="small" @change.native="changeStatus(scope.row)">
                <el-radio :label="2" size="mini">{{$t("AppVersion.enable")}}</el-radio>
                <el-radio :label="1" size="mini">{{$t("AppVersion.blockup")}}</el-radio>
            </el-radio-group>
          </template>
        </el-table-column>
        <el-table-column align="center" header-align="center"  :label="$t('user.operation')" width="100" fixed="right">
          <template slot-scope="scope">
                <el-button size="small" type="text" @click="handleUpdate(scope.row)">{{$t('approvalDetail.hitsee')}}
                </el-button>
            </template>
        </el-table-column>
      </el-table>
      <div class="pagination-container">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="listQuery.page"
          :page-sizes="[10, 30, 50]"
          :page-size="listQuery.limit"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        ></el-pagination>
      </div>
    </el-card>
    <el-dialog
      :title="$t('payChannelManager.bankCodeList')"
      :visible.sync="dialogFormVisible"
    >
      <div>
        <el-table
          :data="bankListData"
          border
          stripe
          style="width: 100%">
          <el-table-column 
          header-align="center"
          align="center" 
          :label="$t('RiskManager.number')" 
          width="155">
            <template slot-scope="scope">
              <span>{{scope.row.index}}</span>
            </template>
          </el-table-column>
          <!-- 银行编码 -->
          <el-table-column
          header-align="center"
          align="center"
          :label="$t('payChannelManager.bankCode')"
          prop="payBankCode">
          </el-table-column>
        </el-table>
        <div class="pagination-container">
            <el-pagination
            @size-change="handleSizeChangeUserInfo"
            @current-change="handleCurrentChangeUserInfo"
            :current-page="bankListQuery.page"
            :page-sizes="[5, 10, 20, 50]"
            :page-size="bankListQuery.limit"
            layout="total, sizes, prev, pager, next, jumper"
            :total="bankListTotal">
            </el-pagination>
        </div>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
import { getChannels } from "api/customQuery/index";
import {
  page,
  updateById,
  updateEcho
} from 'api/synManager/payChannelManager/index';
export default {
  data() {
    return {
      dialogFormVisible: false,
      listLoading: false,
      total: null,
      listQuery: {
        limit: 10,
        page: 1,
        payCompanyCode: '',
        channel: '',
        type: 1
      },
      tableData: [],
      appChannel: [],
      typeArr: [{
        value: 1,
        label: this.$t('payChannelManager.loanChannel')
      }, {
        value: 2,
        label: this.$t('payChannelManager.repayChannel')
      }, {
        value: 3,
        label: this.$t('payChannelManager.partialRepayChannel')
      }],
      bankListData: [],
      bankListQuery: {
        limit: 5,
        page: 1,
        payCompanyCode: ''
      },
      bankListTotal: null,
      code: null,
    };
  },
  computed: {
    ...mapGetters(["elements", "payChannelPage"])
  },
  created() {
    if (this.payChannelPage.has(this.$route.path)) {
      this.listQuery = this.payChannelPage.get(this.$route.path);
    }
    // 渠道下拉
    getChannels().then(res => {
      this.appChannel = res.data;
      this.listQuery.channel = this.appChannel[0].channel;
      this.getList();
    });
  },
  methods: {
    // 点击查看按钮
    handleUpdate(row) {
      this.dialogFormVisible = true;
      this.code = row.payCompanyCode;
      this.bankListFn();
    },
    // 银行编码列表
    bankListFn() {
      this.bankListQuery.payCompanyCode = this.code;
      updateEcho(this.bankListQuery)
      .then(res => {
        if (res.status === 200) {
          res.data.records.forEach((item, index) => {
            item.index = index + (this.bankListQuery.page - 1) * this.bankListQuery.limit + 1
          })
          this.bankListData = res.data.records;
          this.bankListTotal = Number(res.data.total);
        }
      })
    },
    handleSizeChangeUserInfo(val) {
      this.bankListQuery.limit = val;
      this.bankListFn();
    },
    handleCurrentChangeUserInfo(val) {
      this.bankListQuery.page = val;
      this.bankListFn()
    },
    // 修改状态
    changeStatus(row) {
      let obj = {};
      obj.channelCompanyId = row.id;
      obj.status = row.status;
      updateById(obj).then(res => {
        if (res.status === 200) {
          this.$message({
            showClose: true,
            type: "success",
            message: this.$t("approvalDispatch.opersuccess")
          });
          this.getList();
        } else {
          this.$message({
            showClose: true,
            type: "warning",
            message: res.message
          });
          this.getList();
        }
      });
    },
    getList() {
      this.listLoading = true;
      this.$store.dispatch("savePayChannelPage", {
        path: this.$route.path,
        listQuery: this.listQuery
      });
      page(this.listQuery).then(res => {
        if (res.status === 200) {
          res.data.records.forEach((item, index) => {
            item.index =
              index + (this.listQuery.page - 1) * this.listQuery.limit + 1;
          });
          this.listLoading = false;
          this.tableData = res.data.records;
          this.total = Number(res.data.total);
        } else {
          this.$message({
            showClose: true,
            type: "warning",
            message: res.message
          });
        }
      });
    },
    //查询
    search() {
      this.listQuery.page = 1;
      this.getList();
    },
    handleSizeChange(val) {
      this.listQuery.limit = val;
      this.getList();
    },
    handleCurrentChange(val) {
      this.listQuery.page = val;
      this.getList();
    }
  }
};
</script>

<style scoped lang='scss'>
.box-card {
  width: 95%;
  margin-left: 2.5%;
  margin-right: 2.5%;
}
.title {
  line-height: 30px;
  font-size: 16px;
  display: flex;
  align-items: center;
  font-weight: bold;
}
.title:before {
  display: block;
  content: "";
  width: 3px;
  height: 16px;
  background-color: #309afe;
}
.title:before {
  margin-right: 8px;
}
::before {
  box-sizing: inherit;
  -webkit-tap-highlight-color: transparent;
}
.menu-title {
  width: 100%;
  box-sizing: border-box;
  background: #ffffff;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  .searchItem {
    display: flex;
    align-items: center;
    padding: 10px 0;
    span {
      display: inline-block;
      width: 100px;
      text-align: right;
      font-size: 12px;
      color: #5f5f61;
      padding-right: 5px;
    }
    div:nth-child(2) {
      width: 200px;
    }
  }
  .searchItem-date {
    display: flex;
    align-items: center;
    padding: 10px 0;
    b {
      margin: 0 10px;
      font-weight: normal;
      font-size: 12px;
      color: #5f5f61;
    }
    div {
      width: 150px;
    }
  }
}
.menu-title-btn {
  padding: 10px 0;
  box-sizing: border-box;
  button {
    padding: 0 20px;
    height: 28px;
    background: #20a0ff;
    color: #fff;
    outline: none;
    border-width: 0;
    border-radius: 4px;
    font-size: 12px;
    margin-left: 10px;
    &:nth-child(1) {
      margin-left: 0;
    }
    &:nth-child(2) {
      background: #ebf5ff;
      color: #20a0ff;
      border: 1px solid #abd5ff;
    }
  }
  button[disabled] {
    padding: 0 20px;
    height: 28px;
    background: #c1e0ff;
    color: #fafbff;
    outline: none;
    border-width: 0;
    border-radius: 4px;
    font-size: 12px;
  }
}
.menu-list {
  button {
    padding: 0 20px;
    height: 28px;
    background: #20a0ff;
    color: #fff;
    outline: none;
    border-width: 0;
    border-radius: 4px;
    font-size: 12px;
    margin-left: 10px;
    &:nth-child(1) {
      margin-left: 0;
    }
  }
  button[disabled] {
    padding: 0 20px;
    height: 28px;
    background: #c1e0ff;
    color: #fafbff;
    outline: none;
    border-width: 0;
    border-radius: 4px;
    font-size: 12px;
  }
}
.item_bock {
  width: 100%;
  background: #fff;
  display: flex;
  flex-direction: column;
}
.head_img {
  width: 100%;
  height: 200px;
  border: 1px solid #ccc;
  margin-bottom: 10px;
  border-radius: 4px;
}
.head_img img{
  width: 100%;
  height: 200px;
  border-radius: 4px;
}
.hiddenInput{
  display: none;
}
.click-img {
  width: 100%;
  height: 28px;
  line-height: 28px;
  background: #20a0ff;
  color: #fff;
  outline: none;
  border-width: 0;
  font-size: 12px;
  border-radius: 4px;
}
</style>